package com.lxy.util;



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class MyUrl {

	public static String getDocumentAt(String urlString) {
            StringBuilder sb = new StringBuilder();
		try {
			System.out.println("urlstring->>"+urlString);
			URL url = new URL(urlString);
			URLConnection urlConnection = url.openConnection();
			InputStreamReader isr=new InputStreamReader(urlConnection.getInputStream(),"UTF-8");
			System.out.println("encoding:"+isr.getEncoding());
			BufferedReader br = new BufferedReader(isr);
			
			String line = null;
			
			while ((line = br.readLine()) != null) {
				sb.append(line + "\n");
			}
		} catch (MalformedURLException e) {
			System.out.println("URL-->" + urlString);
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("URL2-->" + urlString);
			e.printStackTrace();
		}
		return sb.toString();
	}

}


